<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>流程管理</title>
<script type="text/javascript">
	var $grid;
	$(function() {
		$('#bpmCategoryId').combotree({
			url : '${ctx}/pub/combotree/bpmCategory',
			method : 'get',
			editable : false,
			idField : 'id',
			textField : 'text',
			parentField : 'pid',
			dataPlain : true
		});
		$('#bpmConfBaseId').combobox({
			url : '${ctx}/bpm/process/pdCombobox',
			method : 'get',
			editable : false,
			idField : 'id',
			textField : 'text',
			dataPlain : true,
			width : 250,
			panelWidth : 260
		});
		$grid = $("#grid").datagrid(
				$.extend(datagridOption, {
					url : "${ctx}/bpm/process/dataGrid",
					columns : [ [
/* 							{
								field : 'ck',
								checkbox : true
							}, */
							{
								field : 'name',
								title : '流程名称',
								sortable : true
							},
							{
								field : 'bpmCategory',
								title : '流程类型',
								sortable : true,
								formatter : function(value, row, index) {
									row['bpmCategoryId'] = value.id;//设置流程类型ID
									return value ? value.codeName : "";
								}
							},
							{
								field : 'bpmConfBase',
								title : '绑定流程定义',
								sortable : true,
								formatter : function(value, row, index) {
									row['bpmConfBaseId'] = value.id;
									return value ? value.processDefinitionId : "";
								}
							},
							{
								field : 'code',
								title : '流程代码',
								sortable : true
							},
							{
								field : 'useTaskConf',
								title : '配置任务负责人',
								formatter : function(value, row, index) {
									return '<input class="easyui-switchbutton" ' + (value == 1 ? "checked" : "")
											+ ' data-options="readonly:true,onText:\'开启\',offText:\'关闭\'">';
								}
							}, {
								field : 'priority',
								title : '顺序',
								sortable : true
							}, {
								field : 'businessFormUrl',
								title : '业务单据',
								sortable : true
							}, {
								field : 'descn',
								title : '描述',
								sortable : true
							} ] ]
				}));
		$grid.datagrid('enableFilter', [ {
			field : 'bpmConfBase',
			searchField : 'bpmConfBase.processDefinitionId'
		}, {
			field : 'bpmCategory',
			searchField : 'bpmCategory.codeName'
		}, {
			field : 'useTaskConf',
			type : 'combobox',
			javaType : 'I',
			options : {
				panelHeight : 'auto',
				data : [ {
					value : '',
					text : '全部'
				}, {
					value : '1',
					text : '开启'
				}, {
					value : '0',
					text : '关闭'
				} ],
				onChange : function(value) {
					if (value == '') {
						$("#grid").datagrid('removeFilterRule', 'useTaskConf');
					} else {
						$("#grid").datagrid('addFilterRule', {
							field : 'useTaskConf',
							op : 'EQ',
							value : value
						});
					}
					$("#grid").datagrid('doFilter');
				}
			}
		} ]);

		$("#useTaskConfSB").switchbutton({
			onText : "开启",
			offText : "关闭",
			checked : true,
			onChange : function(checked) {
				if (checked) {
					$("#useTaskConf").val(1);
				} else {
					$("#useTaskConf").val(2);
				}
			}
		});

		$("#add").click(function() {
			$("#fm").form("clear");
			$("#dlg").dialog("open").dialog("setTitle", "新增");
			$("#fm").form("load", {
				useTaskConf : 2
			})
			$("#euseTaskConfSB").switchbutton('uncheck');
		});

		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "您未选中行，无法编辑",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$("#dlg").dialog("open").dialog("setTitle", "编辑");
				$("#fm").form("load", rowData);
				$("#useTaskConfSB").switchbutton(rowData.useTaskConf == 1 ? "check" : "uncheck");
			}
		});
		$("#delete").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "您未选中行，无法删除",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$.messager.confirm("您确定要进行该操作？", function(c) {
					if (c) {
						$.get("${ctx}/bpm/process/delete/" + rowData.id, function(result) {
							$.messager.show({
								msg : result.msg,
								icon : "info",
								position : "bottomRight"
							});
							if (result.success) {
								$grid.datagrid("reload");
							}
						}, 'json');
					}
				});
			}
		});


		$("#config").click(
				function() {
					var rowData = $grid.datagrid("getSelected");
					if (rowData == null) {
						$.messager.show({
							msg : "您未选中行，无法编辑",
							icon : "warning",
							position : "bottomRight"
						});
					} else {
						window.parent.addTab("processConfig", "[" + rowData.name + "]流程配置", "${ctx}/bpm/confNode?bpmConfBaseId="
								+ rowData.bpmConfBase.id + "&bpmProcessId=" + rowData.id);
					}
				});
		$("#excelImport").click(function() {
			$.easyui.importor.showImportor({
				importNo : "EE",
				onExportSuccess : function(file, data) {
					$grid.datagrid('load');
				}
			});
		});
		$("#excelExport").click(function() {
			window.parent.location.href = "${ctx}/bpm/process/excelExport?" + $.param($grid.datagrid('options').queryParams);
		});
	});
	function fn_save() {
		$("#fm").form("submit", {
			url : "${ctx}/bpm/process/update",
			success : function(data) {
				$grid.datagrid("load");
				$.messager.show({
					msg : data.msg,
					icon : "info",
					position : "bottomRight"
				});
				$("#dlg").dialog('close');
			}
		});
	}
</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="easyui-toolbar">
		<div class="row"></div>
		<div class="col-md-12">
			<shiro:hasPermission name="bpmProcess:update">
				<button id="add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增
				</button>
				<button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="bpmProcess:delete">
				<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
			</shiro:hasPermission>
			<div class="dialog-tool-separator"></div>
			<shiro:hasPermission name="bpmProcess:config">
				<button id="config" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-cog"></span> 配置
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="bpmProcess:export">
				<button id="excelImport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-open"></span> Excel导入
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="bpmProcess:import">
				<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导出
				</button>
			</shiro:hasPermission>
		</div>
	</div>
	<shiro:hasPermission name="bpmProcess:update">
		<div id="dlg" class="easyui-dialog" style="width: 670px; height: 350px; padding: 10px 20px"
			data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
			<form id="fm" method="post">
				<input type="hidden" name="id" />
				<table id="tbl">
					<tr>
						<td><label>流程名称:</label></td>
						<td><input name="name" class="easyui-validatebox" data-options="required:true"></td>
						<td><label>流程分类:</label></td>
						<td><input id="bpmCategoryId" name="bpmCategoryId" data-options="required:true"></td>
					</tr>
					<tr>
						<td><label>业务单据:</label></td>
						<td><input name="businessFormUrl" class="easyui-textbox"></td>

						<td><label>排序:</label></td>
						<td><input name="priority" class="easyui-validatebox" data-options="required:true"></td>
					</tr>
					<tr>
						<td><label>绑定流程定义:</label></td>
						<td colspan="3"><input id="bpmConfBaseId" name="bpmConfBaseId" data-options="required:true"></td>
					</tr>
					<tr>
						<td><label>配置任务负责人:</label></td>
						<!-- zst删除class="easyui-validatebox" -->
						<td><input type="hidden" id="useTaskConf" name="useTaskConf"> <input id="useTaskConfSB"></td>
					</tr>
					<tr>
						<td><label>描述:</label></td>
						<td colspan="4"><input name="descn" class="easyui-textbox" data-options="multiline:true,width:449,height:60"></td>
					</tr>
				</table>

			</form>
			<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary" onclick="fn_save();">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</div>
	</shiro:hasPermission>
</body>
</html>
